//
//  ViewController.m
//  ZHD_address book
//
//  Created by Macmini on 17/9/22.
//  Copyright © 2017年 Macmini. All rights reserved.
//

#import "ViewController.h"
#import "ContactpersonViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
{
    UITableView *tableView;
    NSMutableArray *tels;
    NSArray *backup;
    NSArray *data;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"通讯录";
    tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
    tels = [NSMutableArray new];
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"tongxulu(1)" ofType:@"plist"];
    NSLog(@"%@",path);
    data = [NSArray arrayWithContentsOfFile:path];

    //NSLog(@"数据：%@",data);
    int i = 1;
        for(NSDictionary *dict in data){
            NSLog(@"第%d个数据:%@,%@",i++,dict[@"name"],dict[@"tel"]);
            
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    NSDictionary *dict = data[indexPath.row];
    cell.textLabel.text = dict[@"name"];
    cell.detailTextLabel.text = dict[@"tel"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = data[indexPath.row];
    ContactpersonViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactpersonVC"];
    
    VC.name = dict[@"name"];
    VC.tel = dict[@"tel"];
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
